from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-31 14:11:21.648019
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 31, Mar, 2021
Time: 14:11:25
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.2323
Nobs: 247.000 HQIC: -47.9962
Log likelihood: 2926.81 FPE: 8.55262e-22
AIC: -48.5110 Det(Omega_mle): 5.98375e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.448666 0.127932 3.507 0.000
L1.Burgenland 0.071458 0.063262 1.130 0.259
L1.Kärnten -0.217151 0.054571 -3.979 0.000
L1.Niederösterreich 0.085120 0.140622 0.605 0.545
L1.Oberösterreich 0.219533 0.130739 1.679 0.093
L1.Salzburg 0.265396 0.070883 3.744 0.000
L1.Steiermark 0.137978 0.091647 1.506 0.132
L1.Tirol 0.114010 0.062130 1.835 0.067
L1.Vorarlberg -0.031072 0.057425 -0.541 0.588
L1.Wien -0.080644 0.117861 -0.684 0.494
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.479246 0.152666 3.139 0.002
L1.Burgenland 0.006301 0.075493 0.083 0.933
L1.Kärnten 0.338127 0.065122 5.192 0.000
L1.Niederösterreich 0.110967 0.167810 0.661 0.508
L1.Oberösterreich -0.081510 0.156016 -0.522 0.601
L1.Salzburg 0.214102 0.084587 2.531 0.011
L1.Steiermark 0.121527 0.109365 1.111 0.266
L1.Tirol 0.136313 0.074142 1.839 0.066
L1.Vorarlberg 0.156142 0.068527 2.279 0.023
L1.Wien -0.468783 0.140648 -3.333 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.300451 0.062310 4.822 0.000
L1.Burgenland 0.096867 0.030812 3.144 0.002
L1.Kärnten -0.015557 0.026579 -0.585 0.558
L1.Niederösterreich 0.048956 0.068491 0.715 0.475
L1.Oberösterreich 0.287571 0.063677 4.516 0.000
L1.Salzburg 0.017099 0.034524 0.495 0.620
L1.Steiermark 0.019013 0.044637 0.426 0.670
L1.Tirol 0.067175 0.030261 2.220 0.026
L1.Vorarlberg 0.084405 0.027969 3.018 0.003
L1.Wien 0.099597 0.057405 1.735 0.083
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214816 0.063780 3.368 0.001
L1.Burgenland 0.021291 0.031539 0.675 0.500
L1.Kärnten 0.008513 0.027206 0.313 0.754
L1.Niederösterreich 0.047875 0.070107 0.683 0.495
L1.Oberösterreich 0.401913 0.065180 6.166 0.000
L1.Salzburg 0.081924 0.035339 2.318 0.020
L1.Steiermark 0.134960 0.045690 2.954 0.003
L1.Tirol 0.048570 0.030975 1.568 0.117
L1.Vorarlberg 0.082273 0.028629 2.874 0.004
L1.Wien -0.042016 0.058759 -0.715 0.475
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.515706 0.124856 4.130 0.000
L1.Burgenland 0.081721 0.061741 1.324 0.186
L1.Kärnten 0.009985 0.053259 0.187 0.851
L1.Niederösterreich -0.029426 0.137242 -0.214 0.830
L1.Oberösterreich 0.136155 0.127596 1.067 0.286
L1.Salzburg 0.056445 0.069179 0.816 0.415
L1.Steiermark 0.089418 0.089443 1.000 0.317
L1.Tirol 0.212125 0.060637 3.498 0.000
L1.Vorarlberg 0.030930 0.056044 0.552 0.581
L1.Wien -0.094050 0.115027 -0.818 0.414
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.193498 0.097058 1.994 0.046
L1.Burgenland -0.015709 0.047995 -0.327 0.743
L1.Kärnten -0.017281 0.041402 -0.417 0.676
L1.Niederösterreich -0.028862 0.106686 -0.271 0.787
L1.Oberösterreich 0.421317 0.099188 4.248 0.000
L1.Salzburg 0.010009 0.053777 0.186 0.852
L1.Steiermark -0.009786 0.069530 -0.141 0.888
L1.Tirol 0.158947 0.047136 3.372 0.001
L1.Vorarlberg 0.059231 0.043566 1.360 0.174
L1.Wien 0.234051 0.089417 2.618 0.009
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.248148 0.120497 2.059 0.039
L1.Burgenland 0.018631 0.059586 0.313 0.755
L1.Kärnten -0.063519 0.051400 -1.236 0.217
L1.Niederösterreich -0.058934 0.132450 -0.445 0.656
L1.Oberösterreich 0.013835 0.123141 0.112 0.911
L1.Salzburg 0.076363 0.066764 1.144 0.253
L1.Steiermark 0.337984 0.086321 3.915 0.000
L1.Tirol 0.456443 0.058520 7.800 0.000
L1.Vorarlberg 0.148712 0.054087 2.749 0.006
L1.Wien -0.172391 0.111011 -1.553 0.120
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.138656 0.142197 0.975 0.330
L1.Burgenland 0.050023 0.070316 0.711 0.477
L1.Kärnten -0.070173 0.060656 -1.157 0.247
L1.Niederösterreich 0.194470 0.156303 1.244 0.213
L1.Oberösterreich -0.006196 0.145318 -0.043 0.966
L1.Salzburg 0.203404 0.078787 2.582 0.010
L1.Steiermark 0.117556 0.101866 1.154 0.248
L1.Tirol 0.055701 0.069058 0.807 0.420
L1.Vorarlberg 0.100589 0.063828 1.576 0.115
L1.Wien 0.219974 0.131003 1.679 0.093
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.590768 0.077265 7.646 0.000
L1.Burgenland -0.040228 0.038207 -1.053 0.292
L1.Kärnten -0.025632 0.032959 -0.778 0.437
L1.Niederösterreich 0.011437 0.084930 0.135 0.893
L1.Oberösterreich 0.329905 0.078960 4.178 0.000
L1.Salzburg 0.018113 0.042810 0.423 0.672
L1.Steiermark -0.030820 0.055350 -0.557 0.578
L1.Tirol 0.088125 0.037524 2.348 0.019
L1.Vorarlberg 0.110901 0.034682 3.198 0.001
L1.Wien -0.044126 0.071183 -0.620 0.535
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.139597 0.038838 0.160690 0.218704 0.060700 0.077225 -0.003807 0.151879
Kärnten 0.139597 1.000000 0.019091 0.204593 0.178905 -0.064601 0.159499 0.021275 0.306104
Niederösterreich 0.038838 0.019091 1.000000 0.250463 0.068813 0.298751 0.139092 0.029663 0.303401
Oberösterreich 0.160690 0.204593 0.250463 1.000000 0.301929 0.278914 0.088100 0.060464 0.135841
Salzburg 0.218704 0.178905 0.068813 0.301929 1.000000 0.156227 0.048692 0.089570 -0.002096
Steiermark 0.060700 -0.064601 0.298751 0.278914 0.156227 1.000000 0.110496 0.094316 -0.126431
Tirol 0.077225 0.159499 0.139092 0.088100 0.048692 0.110496 1.000000 0.164222 0.144845
Vorarlberg -0.003807 0.021275 0.029663 0.060464 0.089570 0.094316 0.164222 1.000000 0.002661
Wien 0.151879 0.306104 0.303401 0.135841 -0.002096 -0.126431 0.144845 0.002661 1.000000